You are not logged in.
Pages: 1
MongoDB project 24 - MongoDB is not working perfect for me.
It creates successful a database named "test24" with its collections direct and mORMot. My mongo is 2.06.
Another issue that I found out is a small error related to query javascript expression at documentation (BTW, I noticed that mORMot pdf documentation - is particularly slow when you search something.)
FindDoc('{name:"John",age:{$gt,21}}',[]);
FindDoc('{name:?,age:{$gt,?}}',['John',21]));
should be
FindDoc('{name:"John",age:{$gt,21}}',[]);
FindDoc('{name:?,age:{$gt:?}}',['John',21]);
FindCount('{name:?,age:{$gt,?}}',[],['John',21])); --> should be
FindCount('{name:?,age:{$gt:?}}',[],['John',21]);
and others:
_JsonFast('{name:"John",age:{$gt,21}}');
_JsonFastFmt('{name:?,age:{$gt,?}}',[],['John',21]);
FindBSON(BSONVariant('{name:"John",age:{$gt,21}}'),null);
FindBSON(BSONVariant('{name:?,age:{$gt,?}}',[],['John',21]),null);
FindJSON(BSONVariant('{name:"John",age:{$gt,21}}'),null);
Mongo DB
----------
1. Direct access
1.1. Direct with acknowledge:
! - Connect to local server: 1 / 3 FAILED 291.15ms
- Drop and prepare collection: 8 assertions passed 20.12ms
- Fill collection: 303 assertions passed 163.35ms
100 rows inserted in 160.21ms i.e. 624/s, aver. 1.60ms, 187 KB/s
- Drop collection: no assertion 3.76ms
- Fill collection bulk: 2 assertions passed 31.61ms
100 rows inserted in 29.40ms i.e. 3400/s, aver. 294us, 321 KB/s
- Read collection: 603 assertions passed 488.88ms
100 rows read at once in 3.47ms i.e. 28776/s, aver. 34us, 2.1 MB/s
- Update collection: 153 assertions passed 164.34ms
100 rows updated in 99.91ms i.e. 1000/s, aver. 999us, 311 KB/s
! - Delete some items: 2 / 82 FAILED 77.16ms
20 rows deleted in 26.42ms i.e. 756/s, aver. 1.32ms, 152 KB/s
Total failed: 3 / 1,154 - Direct with acknowledge FAILED 1.24s
1.2. Direct without acknowledge:
! - Connect to local server: 1 / 3 FAILED 7.79ms
- Drop and prepare collection: 8 assertions passed 6.48ms
- Fill collection: 303 assertions passed 51.92ms
100 rows inserted in 21.22ms i.e. 4711/s, aver. 212us, 653 KB/s
- Drop collection: no assertion 3.83ms
- Fill collection bulk: 2 assertions passed 26.92ms
100 rows inserted in 24.72ms i.e. 4045/s, aver. 247us, 376 KB/s
- Read collection: 603 assertions passed 482.82ms
100 rows read at once in 3.50ms i.e. 28530/s, aver. 35us, 2.1 MB/s
- Update collection: 153 assertions passed 99.09ms
100 rows updated in 30.15ms i.e. 3315/s, aver. 301us, 501 KB/s
! - Delete some items: 2 / 82 FAILED 63.15ms
20 rows deleted in 5.96ms i.e. 3350/s, aver. 298us, 196 KB/s
Total failed: 3 / 1,154 - Direct without acknowledge FAILED 745.25ms
2. ORM
2.1. ORM with acknowledge:
- Connect to local server: 6 assertions passed 56.65ms
- Insert: 102 assertions passed 149.17ms
100 rows inserted in 144.99ms i.e. 689/s, aver. 1.44ms, 201 KB/s
- Insert in batch mode: 104 assertions passed 31.75ms
100 rows inserted in 30.77ms i.e. 3249/s, aver. 307us, 385 KB/s
- Retrieve: 901 assertions passed 77.65ms
100 rows retrieved in 77.42ms i.e. 1291/s, aver. 774us, 360 KB/s
- Retrieve all: 801 assertions passed 4.61ms
100 rows retrieved in 4.37ms i.e. 22878/s, aver. 43us, 2.5 MB/s
- Retrieve one with where clause: 1,310 assertions passed 86.52ms
100 rows retrieved in 82.26ms i.e. 1215/s, aver. 822us, 339 KB/s
- Update: 802 assertions passed 165.30ms
100 rows updated in 161.52ms i.e. 619/s, aver. 1.61ms, 200 KB/s
- Blobs: 2,503 assertions passed 358.59ms
100 rows updated in 121.50ms i.e. 823/s, aver. 1.21ms, 201 KB/s
- Delete: 763 assertions passed 52.29ms
20 rows deleted in 24.25ms i.e. 824/s, aver. 1.21ms, 135 KB/s
- Delete in batch mode: 663 assertions passed 6.92ms
20 rows deleted in 3.47ms i.e. 5750/s, aver. 173us, 100 KB/s
Total failed: 0 / 7,955 - ORM with acknowledge PASSED 994.02ms
2.2. ORM without acknowledge:
- Connect to local server: 6 assertions passed 12.55ms
- Insert: 102 assertions passed 53.39ms
100 rows inserted in 40.83ms i.e. 2448/s, aver. 408us, 364 KB/s
- Insert in batch mode: 104 assertions passed 20.65ms
100 rows inserted in 15.39ms i.e. 6496/s, aver. 153us, 752 KB/s
- Retrieve: 901 assertions passed 77.43ms
100 rows retrieved in 77.18ms i.e. 1295/s, aver. 771us, 361 KB/s
- Retrieve all: 801 assertions passed 4.07ms
100 rows retrieved in 3.84ms i.e. 26014/s, aver. 38us, 2.8 MB/s
- Retrieve one with where clause: 1,310 assertions passed 86.33ms
100 rows retrieved in 82.12ms i.e. 1217/s, aver. 821us, 339 KB/s
- Update: 802 assertions passed 62.04ms
100 rows updated in 30.68ms i.e. 3258/s, aver. 306us, 534 KB/s
- Blobs: 2,503 assertions passed 216.07ms
100 rows updated in 25.57ms i.e. 3909/s, aver. 255us, 332 KB/s
- Delete: 763 assertions passed 35.71ms
20 rows deleted in 2.58ms i.e. 7739/s, aver. 129us, 334 KB/s
- Delete in batch mode: 663 assertions passed 6.20ms
20 rows deleted in 419us i.e. 47732/s, aver. 20us, 496 KB/s
Total failed: 0 / 7,955 - ORM without acknowledge PASSED 578.85ms
Generated with: Delphi 7 compiler
Time elapsed for all tests: 3.56s
Tests performed at 6/3/2014 3:38:55 PM
Total assertions failed for all test suits: 6 / 18,218
! Some tests FAILED: please correct the code.
----------------------------------------------------------------------------------
20140603 15385224 fail TTestDirectWithAcknowledge(00A2A998) Direct with acknowledge: Connect to local server "" stack trace API 0043E428 0043D705 0043F17D 00436A2B 004374EE 004EA4B6 7C817067
20140603 15385316 warn Test failed
20140603 15385316 fail TTestDirectWithAcknowledge(00A2A998) Direct with acknowledge: Delete some items "" stack trace API 0043E428 0043D705 0043F17D 00436A2B 004374EE 004EA4B6 7C817067
20140603 15385318 warn Test failed
20140603 15385318 fail TTestDirectWithAcknowledge(00A2A998) Direct with acknowledge: Delete some items "" stack trace API 0043E428 0043D705 0043F17D 00436A2B 004374EE 004EA4B6 7C817067
20140603 15385321 warn Test failed
20140603 15385321 fail TTestDirectWithoutAcknowledge(00A2A9F0) Direct without acknowledge: Connect to local server "" stack trace API 0043E428 0043D705 0043F17D 00436A2B 004374EE 004EA4B6 7C817067
20140603 15385401 warn Test failed
20140603 15385401 fail TTestDirectWithoutAcknowledge(00A2A9F0) Direct without acknowledge: Delete some items "" stack trace API 0043E428 0043D705 0043F17D 00436A2B 004374EE 004EA4B6 7C817067
20140603 15385401 warn Test failed
20140603 15385401 fail TTestDirectWithoutAcknowledge(00A2A9F0) Direct without acknowledge: Delete some items "" stack trace API 0043E428 0043D705 0043F17D 00436A2B 004374EE 004EA4B6 7C817067
------------------------------------------------------------------------------------
Offline
What is the exact failing tests? You did not enable "detailed map file" in the project options, so the stack trace does not give the line numbers, but the hexa addresses... impossible to find out what's wrong.
I just tested with MongoDB 2.6.1, with no problem of connection.
We have fixed the doc typos.
Thanks for the feedback.
Offline
line 146 // if CheckFailed(errmsg='') or CheckFailed(not VarIsNull(res.system)) then
line 294// Check(Coll.Count=fExpectedCount);
line 312// Check(Coll.Count=fExpectedCount);
and ! All tests passed successfully.
My mongo-32-bit-2.06 it is not recommended for production nor development - just for tests.
Offline
In java
MongoClient client = new MongoClient(new ServerAddress("localhost",27017) );
DB database = client.getDB("test24");
DBCollection collection = database.getCollection("direct");
DBObject document = collection.findOne();
System.out.println(document);
result is: { "_id" : { "$oid" : "539e0c19553b20080b34c637"} , "Name" : "Name 2" , "FirstName" : "FirstName 101" , "Number" : 1 , "Date" : { "$date" : "1982-02-19T00:00:00.000Z"}}
in mORMot
fClient := TMongoClient.Create('localhost',27017);
fDB := fClient.Database['test24'];
fCollection := fDB.Collection['direct'];
DBObject := fCollection.FindOne(ObjectId('539e0c19553b20080b34c637'));
memo1.Lines.Add(VariantToUTF8(DBObject));
result is: {"_id":{"$oid":"539E0C19553B20080B34C637"},"Name":"Name 2","FirstName":"FirstName 101","Number":1,"Date":"1982-02-19"}
Any idea how can I retrieve the first document ObjectId?
Offline
I suppose it is enough to set NumberToReturn=1 with a void search criteria:
var docs: variant;
Coll.FindDocs(docs,null,1);
memo1.Lines.Add(string(VariantSaveMongoJSON(docs,modMongoShell))); // to see extended MongoDB JSON syntax
Offline
Thank you, this work for me.
DBObject := fCollection.FindDoc(DBObject,null,0); ==> SELECT * from DIRECT
DBObject := fCollection.FindDoc(DBObject,null,1); ==> SELECT * from DIRECT LIMIT 1
result is: {_id:ObjectId("539E0C19553B20080B34C637"),Name:"Name 2",FirstName:"FirstName 101",Number:1,Date:ISODate("1982-02-19")}
Offline
Comparing Mongo java driver with mORMot, one feature missing is sorting.
Supposed you had the following documents in a collection named things.
{ "_id" : 0, "value" : 10 }
{ "_id" : 1, "value" : 5 }
{ "_id" : 2, "value" : 7 }
{ "_id" : 3, "value" : 20 }
Using java, If you perform the following query:
collection.find().sort(new BasicDBObject("value", -1)).skip(2).limit(1);
The document with _id=2 will be returned.
Offline
You can use an aggregate $sort operator.
See AggregateDocs() method.
Offline
I think that AggregateDocs() and AggregateJSON() methods are not supported in my Mongo.
My old MongoDB shell version 2.0.4 say that aggregate is not a function. It supports:
db.myColl.find(...).count()
db.myColl.find(...).limit(n)
db.myColl.find(...).skip(n)
db.myColl.find(...).sort(...)
db.myColl.findOne([query])
db.myColl.findAndModify()
db.myColl.getDB()
db.myColl.getIndexes()
db.myColl.group()
db.myColl.mapReduce()
db.myColl.remove(query)
db.myColl.renameCollection()
db.myColl.runCommand( name , <options> )
db.myColl.save(obj)
db.myColl.stats()
db.myColl.storageSize()
db.myColl.totalIndexSize()
db.myColl.totalSize()
db.myColl.update
db.myColl.validate( <full> )
db.myColl.getShardVersion()
db.myColl.getShardDistribution()
Offline
Yes you need version 2.2....
http://docs.mongodb.org/manual/core/agg … -pipeline/
Your version is more than two years old!
Offline
Is it possible to make a case-insensitive query with multiple fields?
a := QuotedStr(txtname.Text,'"');
b := QuotedStr(txtyear.Text,'"');
DBObject := fCollection.FindJSON('{name:?,year:?}',
[BSONVariant('{$and:[{"$regex": '+a+', $options: "i"},
{"$regex": '+b+', $options: "i"}]}' )] ) ;
DBObject := fCollection.FindJSON(null,'{"$and":[{"name":{"$regex":/CH/i}},
{"year":{"$regex":2012/i}}]}' ) ;
Offline
Offline
I recently have installed the dead kylix3 to play with CrossKylix, but unfortunately I couldn't find out a way to port a wine cellar demo mORMot-MongoDB to run on linux platform. This is possible?
In my demo, I have I have a MongoDB wine collection where field "name" is OWEN ROE "EX UMBRIS"
{
"_id" : ObjectId("53a4a8ed42d644e98541bf8d"),
"name" : "OWEN ROE \"EX UMBRIS\"",
"year" : "2009",
"grapes" : "Syrah",
"country" : "USA",
"region" : "Washington",
"description" : "A one-two punch of black pepper and jalapeno will send
your senses reeling, as the orange essence snaps you back to reality. Don't miss
this award-winning taste sensation.",
"picture" : "ex_umbris.jpg"
}
if i update with:
fCollection.Update('{_id:?}',[ObjectId(txtID.Text)],'{$set:{name:?,year:?,grapes:?,country:?,region:?,description:?,picture:?}}',[txtname.Text,txtyear.Text, txtgrapes.Text, txtcountry.Text,txtregion.Text,txtdescription.Lines.Text,txtphoto.Text]);
txtname.Text = OWEN ROE "EX UMBRIS" mORMot
{
"_id" : ObjectId("53a4a8ed42d644e98541bf8d"),
"country" : "USA",
"description" : "A one-two punch of black pepper and jalapeno will send
your senses reeling, as the orange essence snaps you back to reality. Don't miss
this award-winning taste sensation.",
"grapes" : "Syrah",
"name" : "OWEN ROE ",
"picture" : "ex_umbris.jpg",
"region" : "Washington",
"year" : "2009"
}
Everything is fine if I use TDocVariant to save/update a document.
Offline
There is no CrossKylix/Kylix support yet.
There was indeed a problem with string values JSON string encoding.
See http://synopse.info/fossil/info/7c3529beb377278b
Offline
Master-detail with mongoDB
=====================
I have a MongoDB with nested documents, like this:
{
"_id" : ObjectId("53a4a9dd42d644e98541bfa1"),
"name" : "WATERBROOK",
"year" : "2009",
"grapes" : "Merlot",
"country" : "USA",
"region" : "Washington",
"description" : "Legend has it the gods didn't share their ambrosia with mere mortals. This merlot may be the closest we've ever come to a taste of heaven.",
"picture" : "waterbrook.jpg",
"items" : [
{
"sku" : "Type A",
"quantity" : 3,
"price" : 17.5
},
{
"sku" : "Type B",
"quantity" : 2,
"price" : 18.5
}
]
}
I'd like to modify items using StringGrid?
So, I have a TStringGrid, and I want to delete, update, insert new "items" then saving to a collection.
This is my current StringGrid1:
-------------------------------
sku quantity price
-------------------------------
Type A 3 17.5
Type B 2 18.5
-------------------------------
I tried ToDocVariant procedure but I only get Json for the current row in a StringGrid.
for i := 1 to StringGrid1.RowCount-1 do begin
fGrid.Table.ToDocVariant(i,doc);
ShowMessage(doc);
end;
output is:
{'sku':'Type A','quantity':3,'price':17.50} // when i = 1
{'sku':'Type B','quantity':2,'price':18.50} // when i = 2
The biggest problem I have is to get this json array output from a StringGrid:
[{'sku':'Type A','quantity':3,'price':17.50},{'sku':'Type B':'quantity':2,'price':18.50}]
Any idea?
Offline
Bye, bye Chile. After a tense match, Brazil breathes giant siggt of relief, defeats Chile on penaults.
If you don't know Chile is fortunate to have climate conditions that are ideal for good wine grapes.
Guess what? I've created an Wine Cellar application powered by Delphi mORMot and MongoDB.
http://youtu.be/qiFq7-Kp6X8
source code:https://www.dropbox.com/s/fc2qxl9fmpi2bho/mongoProj.rar
Last edited by warleyalex (2014-06-30 13:48:10)
Offline
Even if I was born in Bordeaux, France, I find some credit to Chile wineyards...
Thanks for sharing!
I've added a new ThirdPartyDemos folder, and posted your code in there.
See http://synopse.info/fossil/info/6a3d76f048b9e93
and https://github.com/synopse/mORMot/tree/ … PartyDemos
Offline
mORMOT, good wines, a pretty girl and Gustavo Lima's song
Offline
Pages: 1