MongoDB is JSON Document:
How to start MongoDB client:
// Start the server // start the CLI
How to Restore a database:
Mongorestore can create a new database or add data to an existing database.
If you restore to an existing database, Mongorestore 'll only inserts into the existing database, and does not PE Rform updates of any kind. If existing documents has the same value _id field in the target database and collection, Mongorestore Would not overwrite those documents.
Read more:http://docs.mongodb.org/manual/reference/program/mongorestore/
Download the Resoure:http://poeticoding.com/downloads/mongodb/mongodb_poeticoding_blog.zip
How to import the JSON file into database:
Mongoimport--db Simple--collection people--jsonarray Data.json
Read more:http://docs.mongodb.org/manual/reference/program/mongoimport/
Simple Commands:
// Show All the database: show DBS; // Show All collections: show Collections; // Create oruse one database use <database_name>
Insert:
The data you have:
{title:"My First blog post", author:{firstName:"YY", LastName:"KK", Email:"[email protected]"}, Tags: ["Coding","Database"], pubdata:new Date}
Cmd:
//INSERT into the posts collectionDb.posts.insert ({title:"My First blog post", author:{firstName:"YY", LastName:"KK", Email:"[email protected]"}, Tags: ["Coding","Database"], pubdata:new Date});
Note: _id should be unique.
Find:
// get the oldest inserted data Db.posts.findOne (); // getall the data db.posts. Find ();
Db.posts. Find // count the amount
Db.posts. Find // Make output looks pretty
// Find according to the criteria // Find the title which is AngularJSdb.posts. Find " AngularJS " //Find The title whcih contains AngularJSdb.posts. Find
// Find title contains ' iOS ', only show title, not _id in the resultdb.posts. Find ({title:/ios/i}, {title:10});
Javascript code for this: (Something should looks-like)
Posts. Find ({title:/ios/i}). Select ("title"). EXEC (thefunction(err, data) { Response.json ( , data); })
[MongoDB] Insert, Find--1