createSearchIndex() not found in mongosh

Hi,
I’m running mongosh (latest/greatest) from my Window 7 Pro PC against an Atlas-deployed db of mine (version 6.0.6 it says), to test the construction of Atlas Search indexes through mongosh.
I connected to the cluster and entered the shell, then went to the db and showed the collections, just fine.

I picked one collection and called

db.<collection name>.crateSearchIndex("test", {})

expecting some syntax errors, but also trying in any other way, I get

MongoServerError: command not found

Yet, if I try
db.<collection name>.crateSearchIndex
the function appears to be known, showing:

[Function: createSearchIndex] AsyncFunction {
apiVersions: [ 0, 0 ],
returnsPromise: true,
serverVersions: [ ‘6.0.0’, ‘999.999.999’ ],
topologies: [ ‘ReplSet’, ‘Sharded’, ‘LoadBalanced’, ‘Standalone’ ],
returnType: { type: ‘unknown’, attributes: {} },
deprecated: false,
platforms: [ ‘Compass’, ‘Browser’, ‘CLI’ ],
isDirectShellCommand: false,
acceptsRawInput: false,
shellCommandCompleter: undefined,
help: [Function (anonymous)] Help
}

As well as it appears in
db.<collection name>.crateSearchIndex.help()
which shows, among other things,
createSearchIndex Creates one search indexes on a collection

So if it’s “there” and in the help() list, why is it reporting a “not known” error when used?
The user I connect as has readWrite access to the db.

Thanks

You have typed several times crateSearchIndex instead of createSearchIndex.
The first guess which leaps to mind is that you are misspelling the function name sometimes.

1 Like

Jack,
thanks for catching that, but unfortunately that’s not the issue.

Here is the latest output from properly spelled commands:

Atlas atlas-**** [primary] -**** > db.companies.getSearchIndexes()
MongoServerError: $listSearchIndexes is not allowed or the syntax is incorrect,
see the Atlas documentation for more information
Atlas atlas-**** [primary] -**** > db.companies.createSearchIndex()
MongoServerError: command not found

Thanks

Does it work if you try to create an index using Compass?

I am currently on Compass 1.21.1 and I don’t see any way to create an Atlas Search index – native indexes OK, but it doesn’t seem to be there for Atlas Search indexes.
So I can’t seem to be able to try if they work from there.

Hmm, I’m not so clear on the difference between the two types of indexes.

However, the latest version of Compass is 1.38.0 … you might try updating.

Hi there, thanks for posting in the MongoDB Community forum! createSearchIndex() is not yet available in MongoDB v6.0. Work is in progress so please hang tight! We will update here when it becomes available.

3 Likes

Hello Amy,
thanks for the clarification, but… ah! It didn’t really come across clearly from the documentation…

At any rate, the post you refer to, where updates should appear on the matter is already 4 years old… it doesn’t seem the matter has been MongoDB’s priority…
Can you share some info on the timeframe when this capability could be available?

Alternatively, is there a way to create Atlas Search indexes via a more recent Compass version as Jack hypothesized?

Alternatively yet, any way at all to create these indexes in a scripting context, or do I have to resort to other options, say a mini NodeJS app to that end?

Thanks
-stefano

Hi @Stefano_Odoardi , thanks for your feedback on the documentation. We will update it to make this more clear.

The status on the post should show In Progress now, and we expect to be able to deliver support for 6.0 within the next few months. Work to support creating Atlas Search indexes via Compass is also in progress.

In the meanwhile, you can use the Atlas Admin API or Atlas CLI to create search indexes in a scripting context - see docs on different methods here. Let me know if that helps!

1 Like

3 posts were split to a new topic: createSearchIndexes not working