Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To test the SQL Mapping, you can first create a new collection using CREATE COLLECTION and then insert data using INSERT, or you can just insert data using INSERT and a collection will be created if it does not exist. There is no direct mapping for CREATE TABLE.


Anchor
Back to Top
Back to Top

Table of Contents

WHERE SQL Mapping

...

MongoDBADS MongoSQL
db.baseball.find(
{ colors: "white" }
)
SELECT * FROM baseball
WHERE colors = 'white'
db.baseball.find(
{ colors:
	{ $all: [ "orange", "black" ] }
}
)

Note: $all selects the documents where the field holds an 
array and contains all specified elements.

SELECT * FROM baseball
WHERE colors CONTAINS_ALL ('orange', 'black')


db.baseball.find(
{ colors:
	{ $all: [ "orange", "black" ],
	 $size: 2 }
}
)

Note: $size matches any array with the number of elements specified.

SELECT * FROM baseball
WHERE colors CONTAINS_ALL ('orange', 'black') AND
  ARRAY_SIZE(colors) = 2

or
SELECT * FROM baseball
WHERE colors = ['orange', 'black']

db.baseball.find(
{ "stats.year":
	{ "$all": [ 2010, 2011 ] }
}
)
SELECT * FROM baseball
WHERE stats.year CONTAINS_ALL ( 2010, 2011 )
db.baseball.find(
{ stats:
	{ $elemMatch:
		{ wins: { $gt: 80 },
		 winPercentage: { $gt: 0.58 }
		}
	}
}
)

Note: $elemMatch matches more than one component within an array element.
SELECT * FROM baseball
WHERE stats.wins > 80 AND
 stats.winPercentage > 0.58

Back to top

Other WHERE Support

Query Reference: WHERE

...