Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MongoDB Atlas full text search #9115

Closed
sanderfish opened this issue Jun 10, 2020 · 2 comments
Closed

Support MongoDB Atlas full text search #9115

sanderfish opened this issue Jun 10, 2020 · 2 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@sanderfish
Copy link

sanderfish commented Jun 10, 2020

Feature request

MongoDB Atlas announced Atlas Search is now generally available:

https://www.mongodb.com/atlas/search
https://docs.atlas.mongodb.com/atlas-search/

Mongoose (5.9.17) currently doesn't support the Atlas Search $search pipeline in aggregations. It throws the error

MongoError: Unrecognized pipeline stage name: '$search'

It would be amazing if Mongoose could support Atlas Search.

@vkarpov15 vkarpov15 added this to the 5.10 milestone Jun 12, 2020
@vkarpov15 vkarpov15 added the enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature label Jun 12, 2020
@vkarpov15
Copy link
Collaborator

That error comes from MongoDB, not Mongoose. Make sure you're connecting to MongoDB Atlas and your cluster is running at MongoDB 4.2 or higher: https://docs.atlas.mongodb.com/atlas-search/. Below script works fine against my Atlas cluster:

'use strict';
  
const mongoose = require('mongoose');

mongoose.set('useFindAndModify', false);

const { Schema } = mongoose;

run().catch(err => console.log(err));

async function run() {
  await mongoose.connect('mongodb+srv://OMITTED:OMITTED@OMITTED.mongodb.net/sample_mflix?retryWrites=true&w=majority', {
    useNewUrlParser: true,
    useUnifiedTopology: true
  });

  const Movie = mongoose.model('Movie', Schema({
    title: String,
    plot: String
  }));

  const res = await Movie.aggregate([
  {
    $search: {
      "text": {
        "query": "baseball",
        "path": "plot"
      }
    }
  },
  {
    $limit: 5
  },
  {
    $project: {
      "_id": 0,
      "title": 1,
      "plot": 1
    }
  }
  ]);

  console.log('Result', res);
}

That being said, we'll add a Aggregate#search() helper for consistency with other pipeline stages.

@rocknrolla777
Copy link

you could check this package - https://www.npmjs.com/package/mongoose-atlas-search

@Automattic Automattic locked and limited conversation to collaborators Jan 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

4 participants