nodejs-firestore icon indicating copy to clipboard operation
nodejs-firestore copied to clipboard

Value for argument "fieldPath" is not a valid field path when making OR queries

Open jramosss opened this issue 2 years ago • 3 comments

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

  1. Is this a client library issue or a product issue? This is the client library for . We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the Support page to reach the most relevant engineers.

  2. Did someone already solve this?

  • Search the issues already opened: https://github.com/googleapis/nodejs-firestore/issues
  • Search the issues on our "catch-all" repository: https://github.com/googleapis/google-cloud-node
  • Search or ask on StackOverflow (engineers monitor these tags): http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
  1. Do you have a support contract? Please create an issue in the support console to ensure a timely response.

If the support paths suggested above still do not result in a resolution, please provide the following details.

Environment details

  • OS: MacOS Sonoma
  • Node.js version: 18.17.0
  • npm version: 9.6.7
  • @google-cloud/firestore version: 7.1.0

Steps to reproduce

  1. ? Create an OR query over a firestore collection

I'm receiving this error

/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/path.js:606
        throw new Error(`${(0, validate_1.invalidArgumentMessage)(arg, 'field path')} Paths can only be specified as strings or via a FieldPath object.`);
              ^
Error: Value for argument "fieldPath" is not a valid field path. Paths can only be specified as strings or via a FieldPath object.
    at validateFieldPath (/Users/chuls/Documents/sumtech/sendblue/api/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/path.js:606:15)

This is the query

                const userRef = fs.collection('accounts').doc(userID)
                const messagesRef = userRef.collection('messages')
                const lastFetch = new Date()
                const numbersQuery = Filter.or(
                    Filter.where('number', '==', number.replace(' ', '')),
                    Filter.where('number', '==', parseRecipientAsNumber(number))
                )
                messagesRef
                    .where(numbersQuery)
                    .orderBy('date', 'asc')
                    .startAfter(lastFetch)

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

jramosss avatar Dec 12 '23 15:12 jramosss

@jramosss, I attempted a reproduction with this code (guessed on the value of number and return type of parseRecipientAsNumber), but I was not able to reproduce with nodejs-firestore v7.1.0.

The error message appears as if you are using firebase-admin. Can you share how you are importing the package(s) into your code?

MarkDuckworth avatar Dec 27 '23 16:12 MarkDuckworth

@MarkDuckworth Exactly,

import admin from 'firebase-admin'
export const fs = admin.firestore()

jramosss avatar Jan 04 '24 14:01 jramosss

I'm still not able to reproduce this. The following code works fine.

import {initializeApp} from 'firebase-admin/app';
import {Filter, getFirestore, FieldValue} from 'firebase-admin/firestore';
async function main() {
    initializeApp()
    const fs = getFirestore();

    const userID = "foo";
    const userRef = fs.collection('accounts').doc(userID);
    const messagesRef = userRef.collection('messages');

    // Write
    await messagesRef.add({
        number: 1234,
        date: Date.UTC(2024, 1, 1)
    })

    // Read
    const lastFetch = new Date();
    const numbersQuery = Filter.or(
        Filter.where('number', '==', "1234"),
        Filter.where('number', '==', 1234)
    )
    const snap = await messagesRef
        .where(numbersQuery)
        .orderBy('date', 'asc')
        .startAt(lastFetch)
        .get();

    console.log(snap.docs.map(ds => ds.data()));
}

main();

To get the query working as expected, I also changed the definition of lastFetch.

const lastFetch = Date.now();

Can you provide a minimal, reproducible example to help us understand what you are seeing?

MarkDuckworth avatar Jan 08 '24 21:01 MarkDuckworth