Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jramosss opened this issue Dec 12, 2023 · 3 comments
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. needs more info This issue needs more information from the customer to proceed. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jramosss
Copy link

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?

  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 jramosss added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 12, 2023
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Dec 12, 2023
@MarkDuckworth MarkDuckworth self-assigned this Dec 27, 2023
@MarkDuckworth
Copy link
Contributor

@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 MarkDuckworth added the needs more info This issue needs more information from the customer to proceed. label Dec 27, 2023
@jramosss
Copy link
Author

jramosss commented Jan 4, 2024

@MarkDuckworth Exactly,

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

@MarkDuckworth
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. needs more info This issue needs more information from the customer to proceed. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants