MongoDB is JSON Document:

How to start MongoDB client:

mongod //start the server

mongo // 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 will only insert into the existing database, and does not perform updates of any kind. If existing documents have the same value _id field in the target database and collection, mongorestore will 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 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 or use one database
use <database_name>

Insert:

The data you have:

{
title: "My first blog post",
author:{
firstName: "YY",
lastName: "KK",
email: "yy.kk@yykk.com"
},
tags: ["coding", "database"],
pubData: new Date
}

Cmd:

//insert into the posts collection
db.posts.insert({
title: "My first blog post",
author:{
firstName: "YY",
lastName: "KK",
email: "yy.kk@yykk.com"
},
tags: ["coding", "database"],
pubData: new Date
});

Note: _id should be unique.

Find:

//get the oldest inserted data
db.posts.findOne();
//get all the data
db.posts.find();
db.posts.find().count(); //count the amount
db.posts.find().pretty(); //make output looks pretty
//Find according to the criteria

//Find the title which is AngularJS
db.posts.find({title: "AngularJS"}); //Find the title whcih contains AngularJS
db.posts.find({title: /AngularJS/i});
//Find title contains 'ios', only show title, not _id in the result
db.posts.find({title: /ios/i}, {title:, _id: });

Javascript code for this: (something should looks like)

    Posts.find({title: /ios/i}).select("title").exec(function(err, data) {
response.json(, data);
})

[MongoDB] Insert, find -- 1的更多相关文章

  1. mongodb insert()、save()的区别

    mongodb 的 insert().save()  ,区别主要是:若存在主键,insert()  不做操作,而save() 则更改原来的内容为新内容. 存在数据:  { _id : 1, " ...

  2. MongoDB insert/update/one2many案例

    以博文与评论为例,博文有标题内容,对应多个评论,评论有评论人.评论内容等. ()插入一条博文: db.blog.insert( {','title':'this is blog title1','co ...

  3. MongoDB insert performance rapidly dropping

    http://dba.stackexchange.com/questions/65554/mongodb-insert-performance-rapidly-dropping http://www. ...

  4. 【翻译】MongoDB指南/CRUD操作(二)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...

  5. MongoDB - basic

    mongoDB basic from:http://www.tutorialspoint.com/mongodb prject:https://github.com/chenxing12/l4mong ...

  6. 通过mongodb客户端samus代码研究解决查询慢问题

    最近有项目需要用到mongodb,于是在网上下载了mongodb的源码,根据示例写了测试代码,但发现一个非常奇怪的问题:插入记录的速度比获取数据的速度还要快,而且最重要的问题是获取数据的速度无法让人接 ...

  7. mongodb学习2---常用命令解析

    1,mongodb insert()和save()的相同点和区别区别:若新增的数据中存在主键 ,insert() 会提示错误,而save() 则更改原来的内容为新内容.insert({_id : 1, ...

  8. mongodb(基础用法)

    驱动和客户端库 https://mongodb-documentation.readthedocs.org/en/latest/ecosystem/drivers.html#id2 https://m ...

  9. mongodb 和 mysql 的对照

    In addition to the charts that follow, you might want to consider the Frequently Asked Questions sec ...

随机推荐

  1. HighChart 实现从后台取数据来实时更新柱状和折线组图

    前段时间公司让弄图表,给我说有HighCharts这个js插件,于是上网上搜,由于本人是写后端的,对于JavaScript和jQuery不是很熟悉,虽然找到了模板,但是还是不明白,所以一点一点的改,但 ...

  2. Page 63-64 Exercises 2.3.7 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)

    Use the following method printPrimes() for question a-d below //Find and prints n prime integers pri ...

  3. leetcode:Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  4. MATLAB 通过二进制读写文件

    这几天在做信息隐藏方面的应用,在读写文本文件时耗费许久,故特别的上网学习一二,这里给出一常用读写,其他的都类似. 很多时候,我们都要将一个.txt以二进制方式读出来,操作后在恢复成.txt文本. ma ...

  5. Redis中的发布与订阅

    redis中实现发布与订阅相对于zookeeper非常简单.直接使用publish和subscribe就行. subscrible news; 订阅news这个channel publish news ...

  6. 安装VMware-tools的问题

    今天晚上解决了之前在跟着 Linux学习之CentOS(六)--CentOS下VMware-Tools安装 解压部分,cp 压缩文件时,没有通过命令,直接鼠标操作复制到/home/ranjiewen下 ...

  7. 关于微信聊天与朋友圈如何快速切换 Mark

    用微信时,你是否遇到这样的情况.你正刷着朋友圈,享受着各种鸡汤,这时候,你收到一条微信,一看是女王大人,不得不回.你诚恳的回了一条,等了二十秒不见有什么回应,于是就退了出来,进入朋友圈找到那篇没看完的 ...

  8. linux库文件编写入门(笔记)

    linux库文件的编写 作者: laomai地址: http://blog.csdn.net/laomai 本文主要参考了如下资料⑴hcj写的"Linux静态/动态链接库的创建和使用&quo ...

  9. Linux下IP的配置

    修改ip地址1.即时生效:# ifconfig eth0 192.168.1.102 netmask 255.255.255.02.启动生效:修改/etc/sysconfig/network-scri ...

  10. C#读取文件为byte数组

    private byte[] FileContent(string fileName) { using (FileStream fs = new FileStream(fileName, FileMo ...