随笔 - 1635  文章 - 579 评论 - 372 trackbacks - 0

https://blog.csdn.net/qq_34579060/article/details/79408979

集合中的数据如下:

 

{
   title: 'MongoDB Overview', 
   description: 'MongoDB is no sql database',
   by_user: 'runoob.com',
   url: 'http://www.runoob.com',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 100
},
{
   title: 'NoSQL Overview', 
   description: 'No sql database is very fast',
   by_user: 'runoob.com',
   url: 'http://www.runoob.com',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 10
},
{
   title: 'Neo4j Overview', 
   description: 'Neo4j is no sql database',
   by_user: 'Neo4j',
   url: 'http://www.neo4j.com',
   tags: ['neo4j', 'database', 'NoSQL'],
   likes: 750
},

如果使用如下操作,只会插入第一条数据

 

db.col.insert(
  {  
   "title": 'MongoDB Overview', 
   "description": 'MongoDB is no sql database',
   "by_user": 'runoob.com',
   "url": 'http://www.runoob.com',
   "tags": ['mongodb', 'database', 'NoSQL'],
   "likes": 100
  },
  {
   "title": 'MongoDB Overview', 
   "description": 'No sql database is very fast',
   "by_user": 'runoob.com',
   "url": 'http://www.runoob.com',
   "tags": ['mongodb', 'database', 'NoSQL'],
   "likes": 10
  },
  {
   "title": 'Neo4j Overview', 
   "description": 'Neo4j is no sql database',
   "by_user": 'runoob.com',
   "url": 'http://www.runoob.com',
   "tags": ['neo4j', 'database', 'NoSQL'],
   "likes": 750
  } 
)

如果一次性插入多条的话,应该如下:

 

db.col.insert(
	[
	  {
	   
	   "title": 'MongoDB Overview', 
	   "description": 'MongoDB is no sql database',
	   "by_user": 'runoob.com',
	   "url": 'http://www.runoob.com',
	   "tags": ['mongodb', 'database', 'NoSQL'],
	   "likes": 100
	},
	{
	  
	   "title": 'MongoDB Overview', 
	   "description": 'No sql database is very fast',
	   "by_user": 'runoob.com',
	   "url": 'http://www.runoob.com',
	   "tags": ['mongodb', 'database', 'NoSQL'],
	   "likes": 10
	},
	{
	  
	   "title": 'Neo4j Overview', 
	   "description": 'Neo4j is no sql database',
	   "by_user": 'runoob.com',
	   "url": 'http://www.runoob.com',
	   "tags": ['neo4j', 'database', 'NoSQL'],
	   "likes": 750
	}]
 )
posted on 2019-05-31 15:13 一天不进步,就是退步 阅读(...) 评论(...)  编辑 收藏