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. backbone-1.3.3源码解析-----------Event

    第一次写,写的不对的请指正 backbone.js中的Event实现了自定义事件.自定义事件就是一个对象的键值对,key为事件名,value为一个function数组.在backbone这个对象中有一 ...

  2. 【LeetCode】165 - Compare Version Numbers

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  3. Python 多线程学习(转)

    转自:http://www.cnblogs.com/slider/archive/2012/06/20/2556256.html 引言 对于 Python 来说,并不缺少并发选项,其标准库中包括了对线 ...

  4. 记录一下ORACLE 10gR2的软件下载地址,备用。

    转载自:http://www.eygle.com/archives/2008/06/10gr2_download_link.html 记录一下ORACLE 10gR2的软件下载地址,备用. 下载OTN ...

  5. C++11 多线程

    C++11开始支持多线程编程,之前多线程编程都需要系统的支持,在不同的系统下创建线程需要不同的API如pthread_create(),Createthread(),beginthread()等,使用 ...

  6. JavaScript高级程序设计(第三版)第二章 在HTML中使用JavaScript

    2.1 <script>元素 <script>定义了下列6个属性: async:可选.表示应该立即下载脚本,但不应妨碍页面的其他操作,比如下载其他资源或等待加载其他脚本.只对外 ...

  7. asp.net mvc 使用Ajax

    使用asp.net mvc 调用Action方法很简单. 一.无参数方法. 1.首先,引入jquery-1.5.1.min.js 脚本,根据版本不同大家自行选择. <script src=&qu ...

  8. geeksforgeeks@ Sorting Elements of an Array by Frequency (Sort)

    http://www.practice.geeksforgeeks.org/problem-page.php?pid=493 Sorting Elements of an Array by Frequ ...

  9. openstack-dbs

    真正的服务器派生出线程 和子进程处理多个连接当允许客户端加入聊天室,他发送的任何一条文本都将广播给聊天室中的每个用户,除非文本是服务器CLI当广播一条消息,消息前面将加上发送者的昵称 以尖括号括住昵称 ...

  10. oracle存储过程返回数据集结果

    MSSQL的存储过程返回数据集好简单,直接SELECT 就可以. ORACLE的存储过程返回数据集必须通过游标. 创建ORACLE存储过程 create or replace procedure cx ...