Regex in collection validator and mongorestore

95 views
Skip to first unread message

Анатолий Смакаев

unread,
Jan 28, 2017, 1:17:32 PM1/28/17
to mongodb-user
Hi.

I have a trouble while restoring db with collection that contains regex in validator in MongoDB 3.2.3.

I use first example from document validation documentation on test db:

db.createCollection( "contacts",
   { validator: { $or:
      [
         { phone: { $type: "string" } },
         { email: { $regex: /@mongodb\.com$/ } },
         { status: { $in: [ "Unknown", "Incomplete" ] } }
      ]
   }
} )

Result is ok. Create a dump:

mongodump --db test

Then I restore it:

mongorestore --db test1 dump/test/

and have an error:

Failed: test1.contacts: error creating collection test1.contacts: error running create command: $regex has to be a string

Looks like mongorestore expect $regex to be only a string contrary to documentation. Of course now I use a string pattern for regex but this situation is strange.

Wan Bachtiar

unread,
Feb 1, 2017, 1:28:48 AM2/1/17
to mongodb-user

I have a trouble while restoring db with collection that contains regex in validator in MongoDB 3.2.3.

Hi,

This $regex issue should be fixed in MongoDB v3.2.4+ (mongorestore).

Also, worth mentioning that the latest stable release for MongoDB v3.2.x is version 3.2.11. See also Upgrade to the Latest Revision of MongoDB

Kind regards,

Wan.

Reply all
Reply to author
Forward
0 new messages