You are not logged in.
I've solved the problem partially.
LColl.FindDocs('{V1:?}', ['6600'], ADocs); ===> Exception occured that "EBSONException : doc.VType = 275"
LColl.FindDocs('{V1:?}', ['6600'], ADocs, 'V1'); ===> Same above
LColl.FindDocs('{V1:?}', ['6600'], ADocs, 'NULL'); ===> **Succeed**
I don't know why succeeded.
Thanks your advice.
I've tried as:
LColl.FindDocs('{V1:{$gt:?}}', ['6600'], ADocs);
Same error is occured.
Also as:
LColl.FindDocs('{V1:?}', ['6600'], ADocs, 'V1'); ==> projcetion parmeter is 'V1'
Same thing.
I think that the problem is not the JSON format but the projection parameter type.
When and How to determine DocVariantType.VarType to 274 ?
And Why TVarData(doc).VType is 275 as different to DocVariantType.VarType?
===============================================
According to the code of TMongoRequest.BSONWriteParam() in synMongoDB.pas,
projection parameter treated as BSONVariantType, but when TBSONVariantData(projection).VBlob is null then typecast as TDocVariantData.
And exception occured.
How to aviod this problem?
Using Debug, I can see that FindDocs function's argument "Projection" has 275 as VType in the TBSONVariant.FromBSONDocument().
And TMongoRequestQuery.Create() -> BSONWriteParam() -> BSONWriteDoc() executed squentially.
In BSONWriteDoc(),
if TVarData(doc).VType<>DocVariantType.VarType then
raise EBSONException.CreateFmt('doc.VType=%d',[TVarData(doc).VType]) else ===> Exception eraise here
TVarData(doc).VType is 275,
DocVariantType.VarType is 274.waht's the meaning of 274 or 275 ?
Hello!
I try to get the documents as "V1" value is greater than "6600" like below:
LColl := FDB.CollectionOrCreate[FMongoCollectionName];
SetLength(ADocs, LDocsCount);
LColl.FindDocs('{V1:{$gt, ?}}', ['6600'], ADocs);but i've got error message as
"EBSONException : doc.VType = 275"What's the problem?
I'm so messy!.
Lutf8: RawUtf8;
Doc2: variant;
...
LUtf8 := VariantSaveJSon(Doc);
Doc2 := _Json(Lutf8);
writeln(Doc2.Value(2)); //<--V1's value 1 is displayed
but,
i := 2;
writeln(Doc2.Value(i)); //<-- Variant method calls not supported
The result is different when constant 2 and variable i for Doc2.value(x).
Please give me some hint.
Hello!
I got some document from MongoDB to TDocVariant like below:
[{"_id":{"$oid":"53D75BD3ACD063FD19EA3250"}, "STime":{"$date":"2014-08-18T08:30:30"}, "V1":"1", "V2":"2"}]
I could get the data "1" at TDocvariant variable Doc.V1 and i want to direct access the value as Doc.Value[x] for "V1".
but i have got error message:
"Variant method calls not supported"
What could i do access the value using index?
I do make some device's monitoring program.
The device status data is saved using TMongoCollection.Insert method by client #1 program to MongoDB in every second.
And the client #2 query the saved data which last inserted document and display them to monitor.
I'm not just want a document ID but a last inserted data.
I have solved above problem as:
Doc := Coll.AggregateDoc('{ $sort : { _id: 1 } }, { $limit : 1 }',[]);
not $natural but _id.
Thanks.
Thanks for your advice.
But when i execute as below:
Doc := Coll.AggregateDoc('{ $sort : { $natural : 1 } }, { $limit : 1 }',[]);
Null is returned to Doc variable.
Of course, Doc := Coll.FindDoc(); is OK!
What is the problem for getting the document?
Give me more advice, please.
Thanks in advance.
Hi!
I'm using mOROot for my private project.
And i want to know how to fetch the latest document from mongoDB server with Direct Access synMongoDB
In googling, i can find some command for mongoDB
db.foo.find().sort({$natural:1}).limit(1);How to implement above command to FindDoc or FindJSON like below:
Client := TMongoClient.Create('host');
DB := Client.Database['dbname'];
Coll := DB.CollectionOrCreate['collect'];
Coll.FindDoc('{ $sort: {_id : -1 } } ', []);help me please.