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. MySQL中批量插入数据

    不管怎么样, 你需要大量的数据, 那么问题来了, 怎么快速地插入呢? 1. 这是我创建的一个批量插入的存储过程… 当然, 你可以把参数去掉, 一次性插入1W, 10W… CREATE DEFINER= ...

  2. linux modprobe.conf怎么不见了—-CentOS 6

    用习惯了CentOS或RHEL的用户或许很熟悉/etc/modprobe.conf文件,系统声卡.网卡.SCSI卡的驱动类型都在这里定义,同样部分动态加载的模块的参数也可以在这个文件中定义,但是在Ce ...

  3. 记一个社交APP的开发过程——基础架构选型(转自一位大哥)

    记一个社交APP的开发过程——基础架构选型 目录[-] 基本产品形态 技术选型 最近两周在忙于开发一个社交App,因为之前做过一点儿社交方面的东西,就被拉去做API后端了,一个人头一次完整的去搭这么一 ...

  4. strtol()函数

    #include <stdlib.h>#include <stdio.h> int main(){ char a[] = "100"; char b[] = ...

  5. javascript 作用域例子

    for(var i=0,l=url1.length;i<l;i++){ var url = url1[i]; setTimeout(function(){ window.open(url); } ...

  6. 流式计算之Storm简介

    Storm是一个分布式的.容错的实时计算系统,遵循Eclipse Public License 1.0,Storm可以方便地在一个计算机集群中编写与扩展复杂的实时计算,Storm之于实时处理,就好比H ...

  7. MapReduce运行时出现java.lang.NoClassDefFoundError

    最近在编写MapReduce程序时遇到了一个错误,错误提示信息为: Error: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.H ...

  8. 第三百五十八天 how can I 坚持

    万事要有度,不要话唠,也不能不说,把握好分寸,今天貌似又说多了. 加了天班,理了个发,还有老爸明天来北京. 还有同学聚会没去,还有金龙让去吃鱼,没去. 还有.小米视频通话还行,能远程控制桌面, 还有, ...

  9. 第三百二十六天 how can I 坚持

    今天元宵节啊,晚上去蓝色港湾看了看灯光节,快冻死了,人倒是挺多. 其他没啥了. 还有晚上吃了几个元宵. 好像冻感冒了,有点头晕. 睡觉.

  10. ubuntu官方源列表网址

    http://wiki.ubuntu.org.cn/%E6%BA%90%E5%88%97%E8%A1%A8 (推荐台湾的源)