search

Home  >  Q&A  >  body text

MongoDB里findOne()是不是相当于SQL中LIMIT 1

看到这个关于SQL中加入 LIMIT 1 是否会更快的问题,/q/10100000001...
老牛我就想起了mongodb里的 findOne

db.collection.findOne(query)

不知道是不是跟SQL的一样,还是说跟db.collection.find().limit(1)一样?

高洛峰高洛峰2800 days ago795

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-21 11:17:25

    The limit() function in mongoDB is the same as the limit in sql. The limit() function in mango is also used after the find() function.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-21 11:17:25

    Although the implementation mechanism is not much different from db.collection.find().limit(1) 差距太多,但用起来和 db.collection.find().limit(1),

    findOne 是 找到第一条,返回数据,然后关闭游标cursor 这些操作一气喝成
    db.collection.find().limit(1) is to first return the cursor, obtain the required data, and then close the cursor

    The specific implementation still depends on the client...

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-21 11:17:25

    One meaning

    reply
    0
  • Cancelreply