Created
July 7, 2017 06:41
-
-
Save Tabrizian/452ac79152bc6a5a34aa5cde707d1c27 to your computer and use it in GitHub Desktop.
Using the in filter in mongodb java driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.MongoClient; | |
import com.mongodb.client.MongoCollection; | |
import com.mongodb.client.MongoDatabase; | |
import static com.mongodb.client.model.Filters.*; | |
import com.mongodb.client.model.CreateCollectionOptions; | |
import com.mongodb.client.model.ValidationOptions; | |
import org.bson.Document; | |
import java.util.Arrays; | |
/** | |
* Created by iman on 7/7/17. | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
MongoClient mongoClient = new MongoClient(); | |
MongoDatabase database = mongoClient.getDatabase("test"); | |
MongoCollection<Document> coll = database.getCollection("myTestCollection"); | |
Document doc = new Document("name", "MongoDB") | |
.append("type", "database") | |
.append("count", 1) | |
.append("versions", Arrays.asList("v3.2", "v3.0", "v2.6")) | |
.append("info", new Document("x", 204).append("y", 102)); | |
coll.insertOne(doc); | |
coll.find(in("count", Arrays.asList(1, 2, 3))).first(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment