写入数组时CouchDB“[Circular]”(CouchDB “[Circular]” when writing to an array)

在CouchDB中,我正在写一个数组并继续收到消息“[Circular]”。 我正在使用Node.js来创建这样写的数据。

假设我在CouchDB中的同一文档中有两个电子邮件对象:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = []

现在在Node.js中我在写之前这样做。

var oldData = readFromCouchDb(); var newData = oldData; newData.verifiedEmail.unshift(newData.unverifiedEmail[0]); writeToCouchDb(newData);

然后,当我在Futon中查看文档时,我看到了:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = "[Circular]"

这里发生了什么?

In CouchDB, I am writing to an array and keep getting the message "[Circular]". I am using Node.js to create the data to be written like this.

Say I have an two email objects in the same document in CouchDB:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = []

Now in Node.js I do this before writing.

var oldData = readFromCouchDb(); var newData = oldData; newData.verifiedEmail.unshift(newData.unverifiedEmail[0]); writeToCouchDb(newData);

Then when I view the document in Futon I see this:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = "[Circular]"

What's going on here?

最满意答案

我发现问题与设置Javascript对象彼此相等的方式的深度有关。

为了解决这个问题,我使用以下代码代替上面的unshift:

newData.verifiedEmail.unshift(JSON.parse(JSON.stringify(newData.unverifiedEmail[0])));

I found out the issue has to do with the depth of the way to set Javascript objects equal to each other.

To solve this, I used the following code in place of the unshift above:

newData.verifiedEmail.unshift(JSON.parse(JSON.stringify(newData.unverifiedEmail[0])));写入数组时CouchDB“[Circular]”(CouchDB “[Circular]” when writing to an array)

在CouchDB中,我正在写一个数组并继续收到消息“[Circular]”。 我正在使用Node.js来创建这样写的数据。

假设我在CouchDB中的同一文档中有两个电子邮件对象:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = []

现在在Node.js中我在写之前这样做。

var oldData = readFromCouchDb(); var newData = oldData; newData.verifiedEmail.unshift(newData.unverifiedEmail[0]); writeToCouchDb(newData);

然后,当我在Futon中查看文档时,我看到了:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = "[Circular]"

这里发生了什么?

In CouchDB, I am writing to an array and keep getting the message "[Circular]". I am using Node.js to create the data to be written like this.

Say I have an two email objects in the same document in CouchDB:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = []

Now in Node.js I do this before writing.

var oldData = readFromCouchDb(); var newData = oldData; newData.verifiedEmail.unshift(newData.unverifiedEmail[0]); writeToCouchDb(newData);

Then when I view the document in Futon I see this:

unverifiedEmail = [{"address":"john@example.com","dateAdded":"1389215329484"}] verifiedEmail = "[Circular]"

What's going on here?

最满意答案

我发现问题与设置Javascript对象彼此相等的方式的深度有关。

为了解决这个问题,我使用以下代码代替上面的unshift:

newData.verifiedEmail.unshift(JSON.parse(JSON.stringify(newData.unverifiedEmail[0])));

I found out the issue has to do with the depth of the way to set Javascript objects equal to each other.

To solve this, I used the following code in place of the unshift above:

newData.verifiedEmail.unshift(JSON.parse(JSON.stringify(newData.unverifiedEmail[0])));