SQL SELECT Statement |
MongoDB find() Statement |
SELECT *
FROM JavaTpoint
|
db.JavaTpoint.find()
|
SELECT id, user_id, status FROM JavaTpoint
|
db.JavaTpoint.find( { }, { user_id: 1, status: 1 } )
|
SELECT user_id, status FROM JavaTpoint
|
db.JavaTpoint.find( { }, { user_id: 1, status: 1, _id: 0 } )
|
SELECT * FROM JavaTpoint WHERE status = "B"
|
db.JavaTpoint.find( { status: "A" } )
|
SELECT user_id, status FROM JavaTpoint WHERE status = "A"
|
db.javaTpoint.find( { status: "A" }, { user_id: 1, status: 1, _id: 0 } )
|
SELECT * FROM JavaTpoint WHERE status != "A"
|
db.JavaTpoint.find( { status: { $ne: "A" } } )
|
SELECT *
FROM JavaTpoint
WHERE status = "A"
AND age = 50
|
db.JavaTpoint.find(
{ status: "A",
age: 50 }
)
|
SELECT *
FROM JavaTpoint
WHERE status = "A"
OR age = 50
|
db.JavaTpoint.find(
{ $or: [ { status: "A" } , { age: 50 } ] }
)
|
SELECT *
FROM JavaTpoint
WHERE age > 25
|
db.JavaTpoint.find(
{ age: { $gt: 25 } }
)
|
SELECT *
FROM JavaTpoint
WHERE age < 25
|
Db.JavaTpoint.find(
{ age: { $lt: 25 } }
)
|
SELECT *
FROM JavaTpoint
WHERE age > 25
AND age <= 50
|
db.JavaTpoint.find(
{ age: { $gt: 25, $lte: 50 } }
)
|
SELECT *
FROM JavaTpoint
WHERE user_id like "%bc%"
|
db.JavaTpoint.find( { user_id: /bc/ } )
-or-
db.JavaTpoint.find( { user_id: { $regex: /bc/ } } )
|
SELECT *
FROM JavaTpoint
WHERE user_id like "bc%"
|
db.JavaTpoint.find( { user_id: /^bc/ } )
-or-
db.JavaTpoint.find( { user_id: { $regex: /^bc/ } } )
|
SELECT *
FROM JavaTPoint
WHERE status = "A"
ORDER BY user_id ASC
|
db. JavaTPoint. find( { status: "A" } ). sort( { user_id: 1 } )
|
SELECT *
FROM JavaTPoint
WHERE status = "A"
ORDER BY user_id ASC
|
db. JavaTPoint. find( { status: "A" } ). sort( { user_id: 1 } )
|
SELECT *
FROM JavaTPoint
WHERE status = "A"
ORDER BY user_id ASC
|
db. JavaTPoint. find( { status: "A" } ). sort( { user_id: 1 } )
|
SELECT *
FROM JavaTPoint
WHERE status = "A"
ORDER BY user_id DESC
|
db. JavaTPoint. find( { status: "A" } ). sort( { user_id: -1 } )
|
SELECT *
FROM JavaTPoint
WHERE status = "A"
ORDER BY user_id DESC
|
db. JavaTPoint. find( { status: "A" } ). sort( { user_id: -1 } )
|
SELECT COUNT(*)
FROM JavaTPoint
|
db. JavaTPoint. count()
or
db. JavaTPoint. find(). count()
|
SELECT COUNT(user_id)
FROM JavaTPoint
|
db. JavaTPoint.count( { user_id: { $exists: true } } )
or
db. JavaTPoint.find( { user_id: { $exists: true } } ).count()
|
SELECT COUNT(*)
FROM JavaTPoint
WHERE age > 30
|
db. JavaTPoint.count( { age: { $gt: 30 } } )
or
db. JavaTPoint.find( { age: { $gt: 30 } } ).count()
|
SELECT DISTINCT(status)
FROM JavaTPoint
|
db. JavaTPoint.aggregate( [ { $group : { _id : "$status" } } ] )
or, for distinct value sets that do not exceed the BSON size limit
db. JavaTPoint.distinct( "status" )
|
SELECT *
FROM JavaTPoint
LIMIT 1
|
db. JavaTPoint.findOne()
or
db. JavaTPoint.find(). limit(1)
|
SELECT *
FROM JavaTPoint
LIMIT 5
SKIP 10
|
db. JavaTPoint.find(). limit(5). skip(10)
|
EXPLAIN SELECT *
FROM JavaTPoint WHERE status = "A"
|
db. JavaTPoint. find( { status: "A" } ). explain()
|