[MongoDB] Insert, find -- 1
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的更多相关文章
- mongodb insert()、save()的区别
mongodb 的 insert().save() ,区别主要是:若存在主键,insert() 不做操作,而save() 则更改原来的内容为新内容. 存在数据: { _id : 1, " ...
- MongoDB insert/update/one2many案例
以博文与评论为例,博文有标题内容,对应多个评论,评论有评论人.评论内容等. ()插入一条博文: db.blog.insert( {','title':'this is blog title1','co ...
- MongoDB insert performance rapidly dropping
http://dba.stackexchange.com/questions/65554/mongodb-insert-performance-rapidly-dropping http://www. ...
- 【翻译】MongoDB指南/CRUD操作(二)
[原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...
- MongoDB - basic
mongoDB basic from:http://www.tutorialspoint.com/mongodb prject:https://github.com/chenxing12/l4mong ...
- 通过mongodb客户端samus代码研究解决查询慢问题
最近有项目需要用到mongodb,于是在网上下载了mongodb的源码,根据示例写了测试代码,但发现一个非常奇怪的问题:插入记录的速度比获取数据的速度还要快,而且最重要的问题是获取数据的速度无法让人接 ...
- mongodb学习2---常用命令解析
1,mongodb insert()和save()的相同点和区别区别:若新增的数据中存在主键 ,insert() 会提示错误,而save() 则更改原来的内容为新内容.insert({_id : 1, ...
- mongodb(基础用法)
驱动和客户端库 https://mongodb-documentation.readthedocs.org/en/latest/ecosystem/drivers.html#id2 https://m ...
- mongodb 和 mysql 的对照
In addition to the charts that follow, you might want to consider the Frequently Asked Questions sec ...
随机推荐
- 我的格斗梦——张龙海(R.J)谈游戏动画师职业(转)
编者按:他是一个生在东北,祖藉却是韩国的年轻人.从小生性好动的他觉得上课 学习十分枯燥,所以高中没毕业便辍学在家.但他仍是一个喜欢动漫.游戏的年轻人,因为热爱所以他用父母给的钱开始了求学之路,在之后的 ...
- Ubuntu上用快捷键关闭没有响应的程序
Linux 上有很多方法可以强制关闭无响应的程序,比如你可以通过按快捷键 Ctrl + Shift + T 来调出 Terminal 或者用 Ctrl + Shift + F1 进入 Console ...
- c++ List、Vector、Stack、Queue使用
一.List使用 引入头文件#include <list> List基本函数Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比 ...
- leetcode oj s_06
public class Solution { public static void main(String[] args) { String s = "PAYPALISHIRING&quo ...
- jq 写法
<!doctype html> <html> <head> <meta charset="utf-8"> <script sr ...
- 关于MAC下的QQ聊天中看不到对方所发的图片解决
使用QQ聊天我们会经常碰到一件让人烦心的事情,那就是别人发的截图自己看不大,是一张裂图(腾讯默认的那张图片).通常有几种情况可以造成这种结果: 第一种原因,网络延迟原因,你的网络不好或者对方的网络不好 ...
- jQuery Callback 函数
@(编程) Callback 函数在当前动画 100% 完成之后执行. jQuery 动画的问题 许多 jQuery 函数涉及动画.这些函数也许会将 speed 或 duration 作为可选参数. ...
- oracle不用tsname文件的时候着怎么办
oracle\product\10.2.0\client_2\odp.net\PublisherPolicy\Policy.9.2.Oracle.DataAccess.config 找到newVers ...
- HDU 4284Travel(状压DP)
HDU 4284 Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...
- C++中使用接口
面向对象的语言诸如JAVA提供了Interface来实现接口,但C++却没有这样一个东西,尽管C++ 通过纯虚基类实现接口,譬如COM的C++实现就是通过纯虚基类实现的(当然MFC的COM实现用了嵌套 ...