[MongoDB] Insert, Find--1

Source: Internet
Author: User
Tags mongodb client mongorestore

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.