Guest User

Untitled

a guest
Feb 6th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. db.createCollection( "accounts",
  2. {
  3. validator: { $and:
  4. [
  5. { username: { $type: "string" } },
  6. { email: { $regex: /@*.*$/ } },
  7. { password: { $type: "string" } }
  8. ]
  9. }
  10. }
  11. )
  12.  
  13. //String createDatabase = "{ 'validator': { '$and':[{ 'username': { '$type': 'string' } },{ 'email': { '$regex': '@*.*$' } },{ 'password': { '$type': 'string' } }]}}";
  14. String createDatabase = " { "validator": { "$and":[{ "username": { "$type": "string" } },{ "email": { "$regex": "@*.*$" } },{ "password": { "$type": "string" } }]}}";
  15. JsonParser jsonParser = new JsonParser();
  16. DBObject dbobj= (DBObject) JSON.parse(createDatabase);
  17. getMongoClient().getDatabase(DATABASE_NAME).createCollection(collectionName, new CreateCollectionOptions().validationOptions(new ValidationOptions().validator((Bson) dbobj)) );
  18.  
  19. {
  20. "validator": { "$and":
  21. [
  22. { "username": { "$type": "string" } },
  23. { "email": { "$regex": "@*.*$" } },
  24. { "password": { "$type": "string" } }
  25. ]
  26. }
  27. }
  28.  
  29. 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