Home > Database > Mysql Tutorial > MongoDB BasicDBObject put方法失败,put值失败原因和解决办法

MongoDB BasicDBObject put方法失败,put值失败原因和解决办法

WBOY
Release: 2016-06-07 14:53:29
Original
1667 people have browsed it

MongoDB BasicDBObject put方法失败,put值失败原因和解决办法 BasicDBObject obj = new BasicDBObject(); obj.put(key,value); 出错原因是因为,key是唯一的 key如果出现相同的,就会覆盖之前的 www.2cto.com 例如: obj.put(a,1); obj.put(b,2); obj.put(c


MongoDB BasicDBObject put方法失败,put值失败原因和解决办法

 

BasicDBObject obj = new BasicDBObject();

 

obj.put(key,value);
 

出错原因是因为,key是唯一的

 

key如果出现相同的,就会覆盖之前的

  www.2cto.com  

例如:

 

obj.put("a",1);

 

obj.put("b",2);

obj.put("c",3);

obj.put("a",5);

 

执行后在数据库里面只有

 

obj.put("b",2);

obj.put("c",3);

obj.put("a",5);//覆盖之前的obj.put("a",1); 因为关键字“a”

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template