0

I am getting a wrong type error with full text search in pymongo. Could not find anything in the docs to clarify this.

Here is the query:

query={'$search': 
          {
          'index': 'title',
          'text': {
            'query': 'paper'
          }
        }
      }

result = db.find({ '$text': query } )

I am getting this error:

OperationFailure: "$search" had the wrong type. Expected string, found object, full error: {'operationTime': Timestamp(1629910737, 1), 'ok': 0.0, 'errmsg': '"$search" had the wrong type. Expected string, found object', 'code': 14, 'codeName': 'TypeMismatch', '$clusterTime': {'clusterTime': Timestamp(1629910737, 1), 'signature': {'hash': b'\r\xbe\x067\xea\xfd:#\x9c\x83\x8b\x1e\xac\x15\x8e\x93\xcb\x06=\xe0', 'keyId': 6959643758958739458}}}

It expects a string but I don't understand where.

4

1 回答 1

0

数据模型:

{
    "title":"paper work"
}

首先,创建索引。

db.collection.createIndex( { title: "text" } )

第二,文本搜索。

db.collection.find( { $text: { $search: "paper" } } )
于 2021-08-27T06:04:16.763 回答