我想list_atttributes从我的 mongo 文档中获取整个字段:
db.config.find({},{list_attributes:1, _id:0});
[
{
list_attributes: {
'0': { field: 'LASTNAME', field_key: 'lastname', dataType: 'text' },
'1': { field: 'FIRSTNAME', field_key: 'firstname', dataType: 'text' },
'2': { field: 'SMS', dataType: 'text' },
'3': {
field: 'DOUBLE_OPT-IN',
dataType: 'category',
order: 1,
catAttrib: { '1': 'Yes', '2': 'No' }
},
'4': { field: 'OPT_IN', dataType: 'boolean', order: 2 },
'5': { field: 'TEST_NUMBER', dataType: 'float', order: 3 },
'6': { field: 'TEST_DATE', dataType: 'date', order: 4 }
}
}
]
我试着这样写:
filter := options.Find().SetProjection(bson.M{"list_attributes": 1})
// Pass the filter to Find() to return a MongoDB cursor
cursor, err := col.Find(ctx, filter)
if err != nil {
log.Fatal("col.Find ERROR:", err)
}
但是游标在这里返回了 0 个结果。
如何bson.M为同一投影创建过滤器?
我正在使用官方的 mongodb 驱动器。
侃侃尔雅
相关分类