Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.createCollection( "accounts",
- {
- validator: { $and:
- [
- { username: { $type: "string" } },
- { email: { $regex: /@*.*$/ } },
- { password: { $type: "string" } }
- ]
- }
- }
- )
- //String createDatabase = "{ 'validator': { '$and':[{ 'username': { '$type': 'string' } },{ 'email': { '$regex': '@*.*$' } },{ 'password': { '$type': 'string' } }]}}";
- String createDatabase = " { "validator": { "$and":[{ "username": { "$type": "string" } },{ "email": { "$regex": "@*.*$" } },{ "password": { "$type": "string" } }]}}";
- JsonParser jsonParser = new JsonParser();
- DBObject dbobj= (DBObject) JSON.parse(createDatabase);
- getMongoClient().getDatabase(DATABASE_NAME).createCollection(collectionName, new CreateCollectionOptions().validationOptions(new ValidationOptions().validator((Bson) dbobj)) );
- {
- "validator": { "$and":
- [
- { "username": { "$type": "string" } },
- { "email": { "$regex": "@*.*$" } },
- { "password": { "$type": "string" } }
- ]
- }
- }
- com.mongodb.MongoCommandException: Command failed with error 2: 'unknown operator: $and' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "unknown operator: $and", "code" : 2, "codeName" : "BadValue" }
Add Comment
Please, Sign In to add comment