pradb>db.t1129_1.find({},{e1:1})
{ “_id” : ObjectId(“5a1e4dfb2f4fc9561273cc6f”), “e1” : [ 800, 900 ] }
{ “_id” : ObjectId(“5a1e4ec02f4fc9561273cc70”) }
{ “_id” : ObjectId(“5a1e4f722f4fc9561273cc71”) }
{ “_id” : 700 }
{ “_id” : ObjectId(“5a279b3c5d11e0a20d21b05e”), “e1” : [ 100, 200 ] }
{ “_id” : ObjectId(“5a279b425d11e0a20d21b05f”), “e1” : [ 201, 300 ] }
{ “_id” : ObjectId(“5a279b425d11e0a20d21b060”), “e1” : [ 301, 400 ] }
{ “_id” : ObjectId(“5a31d7ae3bd6e79f91c6d091”), “e1” : [ 400, 301, 199 ] }
##现在想仅仅返回数组e1中的倒数第一个元素,但是无法做到仅返回e1这个字段
pradb>db.t1129_1.find({},{e1:{$slice:-1}})
{ “_id” : ObjectId(“5a1e4dfb2f4fc9561273cc6f”), “a1” : 12, “nr1” : { “nr11” : 11, “nr12” : 200, “nr13” : 300 }, “a3” : 100, “state” : “normal”, “e1” : [ 900 ] }
{ “_id” : ObjectId(“5a1e4ec02f4fc9561273cc70”), “a1” : 22, “nr1” : { “nr11” : 2100, “nr12” : 400, “nr13” : 500 }, “a3” : 700, “state” : “normal” }
{ “_id” : ObjectId(“5a1e4f722f4fc9561273cc71”), “a1” : 18, “nr1” : { “nr11” : 20, “nr12” : 300, “nr13” : 600 }, “a3” : 200, “state” : “normal” }
{ “_id” : 700 }
{ “_id” : ObjectId(“5a279b3c5d11e0a20d21b05e”), “e1” : [ 200 ] }
{ “_id” : ObjectId(“5a279b425d11e0a20d21b05f”), “e1” : [ 300 ] }
{ “_id” : ObjectId(“5a279b425d11e0a20d21b060”), “e1” : [ 400 ] }
{ “_id” : ObjectId(“5a31d7ae3bd6e79f91c6d091”), “e1” : [ 199 ] }
##调整成这样也不行
pradb>db.t1129_1.find({},{e1:{$slice:-1},e1:1})
{ “_id” : ObjectId(“5a1e4dfb2f4fc9561273cc6f”), “e1” : [ 800, 900 ] }
{ “_id” : ObjectId(“5a1e4ec02f4fc9561273cc70”) }
{ “_id” : ObjectId(“5a1e4f722f4fc9561273cc71”) }
{ “_id” : 700 }
{ “_id” : ObjectId(“5a279b3c5d11e0a20d21b05e”), “e1” : [ 100, 200 ] }
{ “_id” : ObjectId(“5a279b425d11e0a20d21b05f”), “e1” : [ 201, 300 ] }
{ “_id” : ObjectId(“5a279b425d11e0a20d21b060”), “e1” : [ 301, 400 ] }
{ “_id” : ObjectId(“5a31d7ae3bd6e79f91c6d091”), “e1” : [ 400, 301, 199 ] }
如果在指定$slice的情况下,想仅仅返回数组所在的字段,find()命令该怎么写呢?