Following JSON "document" can be stored in Mongo DB:
{ name: 'ercan',
articleCreateDate : new Date('03/28/2011'),
title : 'MongoDB insert query sample...',
detail : {
columnCount : 11,
columnSize : "not set",
active : "true"
},
tags : [ 'mongo', 'insert' ],
comments : [ { name: 'ercan', comment: 'I disagree' },
{ name: 'can', comment: 'Good post' }
]
}
This document stored in a "articles" collection using the shell:
> doc = { name: 'ercan',
... articleCreateDate : new Date('03/28/2011'),
... title : 'MongoDB insert query sample...',
... detail : {
... columnCount : 11,
... columnSize : "not set",
... active : "true"
... },
... tags : [ 'mongo', 'insert' ],
... comments : [ { name: 'ercan', comment: 'I disagree' },
... { name: 'can', comment: 'Good post' }
... ]
... };
> db.articles.insert(doc);
> db.articles.find( { "comments.name" : "ercan" } )
> db.articles.find( { "detail.columnCount" : 11 } )
> db.articles.find( { "tags" : "mongo"})
Comments
Post a Comment