`Namespace <x>.<y> is a view, not a collection` when trying to restore a view dumped as a collection

230 views
Skip to first unread message

asyr...@vase.ai

unread,
Sep 11, 2017, 3:51:58 AM9/11/17
to mongodb-user
Hi,

I'm using mongodump with the `--viewsAsCollection` option to dump a single view.

However, when I try to use mongorestore to restore the bson file, it gives me the error:

2017-09-11T14:44:34.044+0800    error: Namespace <x>.<y> is a view, not a collection

My mongodump command is:
mongodump --host <host> --port <port> --username <someuser> --db <x> --collection <y> --password <somepassword> --authenticationDatabase <x> --viewsAsCollections

The user has a custom role that only grants access to the <y> collection on the <x> database, and the user is defined on the <x> database.

My mongorestore command is:
mongorestore --db <x> --collection <y> dump/<x>/<y>.bson

Running just mongodump also gives the same error as the I run it in the same directory as the dump folder.

Any help would be much appreciated.

Thanks.

Asya Kamsky

unread,
Sep 11, 2017, 3:44:12 PM9/11/17
to mongodb-user
What version of mongodump and mongorestore are you using?  I just ran a quick test and I couldn't reproduce the problem you saw.

Asya


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/efa4f17a-2d66-426d-854f-e38c4ae18134%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
We're Hiring! - https://www.mongodb.com/careers

Asya Kamsky

unread,
Sep 11, 2017, 3:49:34 PM9/11/17
to mongodb-user
Let me clarify - I saw the error Namespace ... is a view, not a collection, but it appeared to dump and restore documents successfully.

Upon closer check, there is something wrong still, so let me figure out what it is, and file an appropriate tools ticket.

Asya



Asya Kamsky

unread,
Sep 11, 2017, 3:56:46 PM9/11/17
to mongodb-user
I think what may have happened is if you once ran the mongodump without the —viewsAsCollections option, then you already dumped out the metadata file for the view.  Now when you run mongodump again the view metadata will still be there and will cause this error/issue on restore.

If you try this mongodump into a new empty collection and then the restore (into a different mongodb instance), do you still have this issue?

Asya


Asya Kamsky

unread,
Sep 11, 2017, 4:05:07 PM9/11/17
to mongodb-user
The underlying issue is that views dumped as collections don't have any metadata and hence they don't overwrite any metadata file that might have already been written out in the same dump directory.

I filed https://jira.mongodb.org/browse/TOOLS-1786 to have this fixed.

Asya

asyr...@vase.ai

unread,
Sep 12, 2017, 9:31:37 AM9/12/17
to mongodb-user
Thanks for the assistance.

Here's my output for mongodump version:
mongodump version: built-without-version-string
git version: built-without-git-spec
Go version: go1.8.3
   os: linux
   arch: amd64
   compiler: gc
OpenSSL version: OpenSSL 1.0.2l  25 May 2017

and for mongorestore version:
mongorestore version: built-without-version-string
git version: built-without-git-spec
Go version: go1.8.3
   os: linux
   arch: amd64
   compiler: gc
OpenSSL version: OpenSSL 1.0.2l  25 May 2017

I run Arch, so I'm using the tools from this package:
https://www.archlinux.org/packages/community/x86_64/mongodb-tools/

I tried deleting the foo.metadata.json file, and restoring with the database and collection options on mongorestore:
mongorestore --collection foo --db bar dump/bar/foo.bson

but it still gives me the error that Namespace.. is a view...

If a view is dumped as a collection, shouldn't the bson look exactly like a collection to mongorestore? In which case, is it possible there's some extra structure in the bson when you dump a view as a collection and that's causing mongorestore to not work?

To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

Asya Kamsky

unread,
Sep 14, 2017, 11:58:01 AM9/14/17
to mongodb-user
If a view is dumped as a collection, shouldn't the bson look exactly like a collection to mongorestore? In which case, is it possible there's some extra structure in the bson when you dump a view as a collection and that's causing mongorestore to not work?

Nope.  You can actually see the BSON by using `bsondump` command directly on the foo.bson file.

Is it possible the database you are restoring to already has this view defined?  

Try the exact same "restore" but with —drop option - that will say "replace this namespace if it already exists with contents from this bson file".

Asya


To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

For more options, visit https://groups.google.com/d/optout.

asyr...@vase.ai

unread,
Sep 15, 2017, 5:21:18 AM9/15/17
to mongodb-user
Looks like that worked. Also created a totally new db and restored after deleting the foo.metadata.json and it worked without any issue.

I guess what must have happened is when I tried to mongorestore initially (with the metadata), that created a view and then died without restoring any documents. Then, subsequent attempts to restore must have failed because the view was already defined.

Thanks!

Reply all
Reply to author
Forward
0 new messages