MongoDB增加字段(key),删除字段(key)

1.删除字段(value):

db.getCollection('userinfo').update(
    // query 
    {
    },
    
    // update 
    {
        $unset:{'last_time':''}
    },
  
    
    // options 
    {
        "multi" : false,  // update only one document 
        "upsert" : true  // insert a new document, if no existing document match the query 
    }
);

2.删除字段(key)

db.getCollection('userinfo').update(
    // query 
    {
    },
    
    // update 
    {
        $unset:{'last_time':''}
    },
    
    false,
    true
);

3.增加字段

db.getCollection('userinfo').update(
    // query 
    { 
    },
    
    // update 
    {
        $set:{last_time:new Date()}
    },
    
    // options 
    {
        "multi" : true,  // update only one document 
        "upsert" : false  // insert a new document, if no existing document match the query 
    }
);

Type Number Type Explanation 
1 Double 浮点型 
2 String UTF-8字符串都可表示为字符串类型的数据 
3 Object 对象,嵌套另外的文档 
4 Array 值的集合或者列表可以表示成数组 
5 Binary data 二进制 
7 Object id 对象id是文档的12字节的唯一 ID 系统默认会自动生成 
8 Boolean 布尔类型有两个值TRUE和FALSE 
9 Date 日期类型存储的是从标准纪元开始的毫秒数。不存储时区 
10 Null 用于表示空值或者不存在的字段 
11 Regular expression 采用js 的正则表达式语法 
13 JavaScript code 可以存放Javasript 代码 
14 Symbol 符号 
15 JavaScript code with scope
16 32-bit integer 32位整数类型 
17 Timestamp 特殊语义的时间戳数据类型 
18 64-bit integer 64位整数类型

猜你喜欢

转载自blog.csdn.net/sunhuansheng/article/details/82882689