有没有办法通过使用monk来简化内容(从mongodb数据中检索的列之一)?
var monk = require('monk'); var db = monk('127.0.0.1:27017/db');
var collection = db.get('content'); newscol.find({}, {}).then((data) => {console.log(data);})
输出:
[
{
_id: 1,
content: 'a b c d e f g h i j k l m n o p q r s t u v w x y z ',
},
{
_id: 2,
content: 'b c d e f g h i j k l m n o p q r s t u v w x y z',
},
{
_id: 3,
content: 'c d e f g h i j k l m n o p q r s t u v w x y z',
}
]
尝试以正常方式检索数据。
但是有没有办法只检索如下内容的前几个单词?
[
{
_id: 1,
content: 'a b c d...',
},
{
_id: 2,
content: 'b c d e...',
},
{
_id: 3,
content: 'c d e f....',
}
]
我正在尝试使用 collection.aggregate 但似乎它对解决问题没有帮助。
var monk = require('monk'); var db = monk('127.0.0.1:27017/db');
var collection = db.get('content'); newscol.find({}, {}).then((data) => {console.log(data);})
Output:
[
{
_id: 1,
content: 'a b c d e f g h i j k l m n o p q r s t u v w x y z ',
},
{
_id: 2,
content: 'b c d e f g h i j k l m n o p q r s t u v w x y z',
},
{
_id: 3,
content: 'c d e f g h i j k l m n o p q r s t u v w x y z',
}
]
Tried to retrieve the data in a normal way.
But is there any way to retrieve only the first few words of the content as below?
[
{
_id: 1,
content: 'a b c d...',
},
{
_id: 2,
content: 'b c d e...',
},
{
_id: 3,
content: 'c d e f....',
}
]
I am trying to use the collection.aggregate but seems it doesn't help with the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mongoplayground
mongoplayground