#1 2014-09-23 12:38:36

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

[mongodb] Replicaset missing type 17 (betTimeStamp)

Hi AB.

I'm playing with MongoDB and replicaset.

Via ORM write in Db without problems, but it always comes out the exception: unknow type 17 (betTimeStamp)

I found where to make the patch, but I do not know what to enter.

procedures TBSONElement.AddMongoJSON (W: TTextWriter; Mode: TMongoJSONMode);
bin label, regex;
begin
   Kind of homes
   betFloat:
     W.Add (PDouble (Element) ^);
   betString, betJS, betDeprecatedSymbol: begin
     W.Add ('"');
     W.AddJSONEscape (data.text, Data.TextLen);
     W.Add ('"');
   end;
   betDoc, betArray:
     BSONListToJSON (Data.DocList, Kind, W, Mode);
   betObjectID: begin
     W.AddShort (BSON_JSON_OBJECTID [false, Mode]);
     W.AddBinToHex (Element, SizeOf (TBSONObjectID));
     W.AddShort (BSON_JSON_OBJECTID [true, Mode]);
   end;
   betTimeStamp: begin
        // ***************************************************************** here
   end;

Offline

#2 2014-09-30 22:19:23

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

Temporary solution: (ignore it)

add two line:

procedure TBSONElement.AddMongoJSON(W: TTextWriter; Mode: TMongoJSONMode);
label bin,regex;
begin
  case Kind of
  betFloat:
    W.Add(PDouble(Element)^);
  betString, betJS, betDeprecatedSymbol: begin
    W.Add('"');
    W.AddJSONEscape(Data.Text,Data.TextLen);
    W.Add('"');
  end;
  betDoc, betArray:
    BSONListToJSON(Data.DocList,Kind,W,Mode);
  betObjectID: begin
    W.AddShort(BSON_JSON_OBJECTID[false,Mode]);
    W.AddBinToHex(Element,SizeOf(TBSONObjectID));
    W.AddShort(BSON_JSON_OBJECTID[true,Mode]);
  end;
  betDeprecatedUndefined:
    W.AddShort(BSON_JSON_UNDEFINED[Mode=modMongoShell]);
  betBinary:
  case Mode of
  modNoMongo:
    W.WrBase64(Data.Blob,Data.BlobLen,true);
  modMongoStrict: begin
    W.AddShort(BSON_JSON_BINARY[false,false]);
    W.WrBase64(Data.Blob,Data.BlobLen,false);
    W.AddShort(BSON_JSON_BINARY[false,true]);
    W.AddBinToHex(@Data.BlobSubType,1);
    W.AddShort('"}');
  end;
  modMongoShell: begin
    W.AddShort(BSON_JSON_BINARY[true,false]);
    W.AddBinToHex(@Data.BlobSubType,1);
    W.AddShort(BSON_JSON_BINARY[true,true]);
    W.WrBase64(Data.Blob,Data.BlobLen,false);
    W.AddShort('")');
  end;
  end;
  betRegEx:
  case Mode of
  modNoMongo:
bin:W.WrBase64(Element,ElementBytes,true);
  modMongoStrict:
    goto regex;
  modMongoShell:
    if (PosChar(Data.RegEx,'/')=nil) and
       (PosChar(Data.RegExOptions,'/')=nil) then begin
      W.Add('/');
      W.AddNoJSONEscape(Data.RegEx,Data.RegExLen);
      W.Add('/');
      W.AddNoJSONEscape(Data.RegExOptions,Data.RegExOptionsLen);
    end else begin
regex:W.AddShort(BSON_JSON_REGEX[0]);
      W.AddJSONEscape(Data.RegEx,Data.RegExLen);
      W.AddShort(BSON_JSON_REGEX[1]);
      W.AddJSONEscape(Data.RegExOptions,Data.RegExOptionsLen);
      W.AddShort(BSON_JSON_REGEX[2]);
    end;
  end;
  betDeprecatedDbptr:
    goto bin; // no specific JSON construct for this deprecated item
  betJSScope:
    goto bin; // no specific JSON construct for this item yet
  betTimeStamp: // <<----------------------------------------------------add this
    goto bin;       // <<----------------------------------------------------add this
  betBoolean:
    W.AddString(JSON_BOOLEAN[PBoolean(Element)^]);
  betDateTime: begin
    W.AddShort(BSON_JSON_DATE[Mode,false]);
    W.AddDateTime(UnixMSTimeToDateTime(PInt64(Element)^));
    W.AddShort(BSON_JSON_DATE[Mode,true]);
  end;
  betNull:
    W.AddShort('null');
  betInt32:
    W.Add(PInteger(Element)^);
  betInt64:
    W.Add(PInt64(Element)^);
  else
  if Kind=betMinKey then
    W.AddShort(BSON_JSON_MINKEY[Mode=modMongoShell]) else
  if Kind=betMaxKey then
    W.AddShort(BSON_JSON_MAXKEY[Mode=modMongoShell]) else
    raise EBSONException.CreateFmt('Unexpected BSON element of type %d',[ord(Kind)]);
  end;
end;

Offline

#3 2014-10-01 09:56:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

Offline

#4 2014-10-01 19:52:23

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

no...

look at optime and electionTime

looks like a base64 ...

this from delphi debugger: "optime":"ï¿°CgAAADYnK1Q="

ResutUTF8: {"set":"rs0",
"date":"2014-10-01T19:47:42",
"myState":1,
"members":[{"_id":0,
"name":"WIN-G1V0GLAHABK:27019",
"health":1,
"state":2,
"stateStr":"SECONDARY",
"uptime":689,
"optime":"￰￰CgAAADYnK1Q=",
"optimeDate":"2014-09-30T21:57:10",
"lastHeartbeat":"2014-10-01T19:47:40",
"lastHeartbeatRecv":"2014-10-01T19:47:41",
"pingMs":0,
"syncingTo":"192.168.172.130:27020"},
{"_id":1,
"name":"192.168.172.130:27018",
"health":1,
"state":2,
"stateStr":"SECONDARY",
"uptime":689,
"optime":"￰CgAAADYnK1Q=",
"optimeDate":"2014-09-30T21:57:10",
"lastHeartbeat":"2014-10-01T19:47:41",
"lastHeartbeatRecv":"2014-10-01T19:47:41",
"pingMs":1,
"syncingTo":"192.168.172.130:27020"},
{"_id":2,
"name":"192.168.172.130:27020",
"health":1,
"state":1,
"stateStr":"PRIMARY",
"uptime":690,
"optime":"￰CgAAADYnK1Q=",
"optimeDate":"2014-09-30T21:57:10",
"electionTime":"￰AQAAALNXLFQ=",
"electionDate":"2014-10-01T19:36:19",
"self":true}],
"ok":1}

Offline

#5 2014-10-01 21:20:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

Yes it is the raw 8 bytes stored as base64.

Offline

#6 2014-10-01 21:33:08

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

but: >>>>ï¿°C<<<<< ?

Offline

#7 2014-10-01 21:54:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

This is our way to indicate that the string is a blob and not plain text.

Offline

#8 2014-10-01 22:04:50

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

I got it.

Now you will write the changes to auto decode it?

Offline

#9 2014-10-02 08:46:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

What do you do with this value?

Getting and updating some documents which contain this value?
Are you sending back the timestamp value to the MongoDB Server? AFAIK those values are for MongoDB internal use only.
We first started to implement the TimeStamp() syntax, but it sounded like not needed since the value was for internal use only.

Offline

#10 2014-10-02 09:47:19

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Re: [mongodb] Replicaset missing type 17 (betTimeStamp)

Personally I only read them.

In the first post you can see the result of:

   resUTF8: = fdb.RunCommand ('replSetGetStatus', res);

Offline

Board footer

Powered by FluxBB