Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Error when persisting nested objects #143

@lfernando-silva

Description

@lfernando-silva

Environment details

  • OS: Linux Mint
  • Node.js version: 8.9.4 LTS
  • npm version: 5.6.0
  • @google-cloud/firestore version: 0.11.2

Steps to reproduce

  1. call function ref.doc(id).set(params, options), which params is a object like:
{
  "notifications": {
    "web": "a random token string"
  },
  "updatedAt": 1519320011313
}

Expected behavior

  • Persist the object

Actual behavior

  • I got error Cannot encode type ([object Object]) to a Firestore Value. The [object Object] is the nested object ( {web : a random token string} ).

I realized the function isPlainObject at line 1428 returns true for {notifications...}, but returns false for the nested object {web: ....}, as it has no Object.prototype property.

//firestore/src/document.js 1428

function isPlainObject(input) {
  return (
    typeof input === 'object' &&
    input !== null &&
    Object.getPrototypeOf(input) === Object.prototype
  );
}

When I tried to force input to be an object

function isPlainObject(input) {
  return (
    typeof input === 'object' &&
    input !== null &&
(Object.getPrototypeOf(input) === Object.prototype) || (Object.getPrototypeOf(Object.create(input)) === Object.prototype)
  );
}

I got another error for the other value at not nested object:
Argument \"data\" is not a valid Document. Object prototype may only be an Object or null: 1519320772620.

Using lodash 's isObject method:

function isPlainObject(input) {
    return require('lodash').isObject(input) //returns true for both objects
}

I got the error
Argument \"data\" is not a valid Document. obj.hasOwnProperty is not a function

How can I handle this problem? Thank you in advance.

Metadata

Metadata

Labels

🚨This issue needs some love.api: firestoreIssues related to the googleapis/nodejs-firestore API.triage meI really want to be triaged.web

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions