gpt4 book ai didi

mysql - MongoDB 相当于 SQL "NOT LIKE"查询

转载 作者:行者123 更新时间:2023-11-29 08:01:26 25 4
gpt4 key购买 nike

我有以下 SQL 语句

SELECT Currency, TransTime, AuthTime FROM MONIES WHERE Currency not like 'USD%';

如果 SQL 语句只是一个“LIKE”查询,它将产生以下 MongoDB 语句

db.MONIES.find({
"Currency": "USD%"
}, {
"Currency": 1,
"TransTime": 1,
"AuthTime": 1
});

这是“NOT LIKE”等价物的正确查询吗?我认为这是正确的 the documentation for the 'not' operator ,但我想再次检查 Stackoverflow

db.MONIES.find({
"Currency": { $not: { $like: 'USD%' } }
}, {
"Currency": 1,
"TransTime": 1,
"AuthTime": 1
});

最佳答案

The page you link实际上有一个你想做的事情的例子:

db.inventory.find( { item: { $not: /^p.*/ } } )

没有 $like 运算符,但 MongoDB 支持 regular expressions

关于mysql - MongoDB 相当于 SQL "NOT LIKE"查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23701993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com