MongoDB NoSQL Odata Rest API


Basic Query

Take a look at SQL example below:

Select * from users

This means all rows and fields in cities table will be returned in query results.

 Using MongoDB will be a little different, which the syntax will be like this:


Same results will be showed and of course, they are the different format.

SQL result:

ID         |    firstName |     middleName |…..


         1 | rupesh  | kumar            | ..

MongoDB Result:

{     "_id" : ObjectId("5cdec4330c069e29f401e11c"),     "role" : "1",     "isActive" : true,     "createdOn" : ISODate("2019-05-17T14:24:51.651Z"),     "firstName" : "rupesh",     "middleName" : "kumar",     "lastName" : "rupak",     "dob" : ISODate("2000-05-24T18:30:00.000Z"),     "gender" : "Male" } In SQL usually using INTEGER or LONG as ID with unique and incremental property and MongoDB basically using ObjectId as id. And here's syntax comparison: SQL        MongoDB            Notes SELECT *              find()     Select clause FROM   -              From clause users                     Table/Collections Name MongoDB: db.getCollection('users').find({"firstName" : "rupesh"})  Update  db.getCollection('users').update(     // query     {          "_id" : ObjectId("5cdec4330c069e29f401e11c")     },     // update     {        "firstName" : "rupesh kumar",         "middleName" : "singh"     },    // options     {         "multi" : false,  // update only one document         "upsert" : false  // insert a new document, if no existing document match the query     } ); Note: If we pass less entity (field only those would be available rest other will override)  Create Index  Remove the content  db.getCollection('users').remove({ '' : '' });

No Comments

    Leave a Reply