Exclude attributes on text search

19 views
Skip to first unread message

Marco

unread,
Sep 25, 2016, 5:29:35 PM9/25/16
to mongodb-user
Hi @all,

how can I exclude attributes from my text search operation? I tried the following:

db.products.find({$text: {$search: "IBM"}}, {score: {$meta: "textScore"}}, {pictures: 0});

I don't want to get the pictures array.

Thanks!

Pooja Gupta

unread,
Sep 28, 2016, 4:34:36 AM9/28/16
to mongodb-user

Hi Marco,

find() command has the following form:

db.collection.find(query, projection)

The score and $meta part in your $text search query, is the projection section of find(). Therefore, you could just add the exclusion of pictures field in the same section. For example:

db.products.find(
 {$text: {$search: "IBM"}}, 
 {score: {$meta: "textScore"}, pictures: 0}
 )

Regards,
Pooja

Reply all
Reply to author
Forward
0 new messages