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

In emulators, realtime database, firestore write (via emulator functions) is showing success but can't see data in the firebase console #1658

Closed
hkchakladar opened this issue Sep 13, 2019 · 10 comments

Comments

@hkchakladar
Copy link

hkchakladar commented Sep 13, 2019

[REQUIRED] Environment info

firebase-tools: 7.3.2

Platform: Ubuntu

[REQUIRED] Test case

In emulator, I'm writing to realtime database and firestore, via emulator functions. The write shows success, but I can't see it's written to db (firestore, rtdb) in firebase console.

[REQUIRED] Steps to reproduce

Cloud functions:

exports.singleTask = functions.https.onRequest((req, res) => {

	return admin.database().ref(`admin/singleTask/done`)
	.transaction((current_value) => {
		console.log(current_value);
		if (current_value === null || current_value === 0) {
			return (current_value || 0) + 1;
		} else {
			//eslint-disable-next-line consistent-return
			return; // Abort the transaction.
		}

	})
	.then((trans) => {
		if (trans.committed) {
		
			return firestore.doc('col/doc1').set({'key': 'val'});
		
		} else {
			return Promise.reject(new Error('duplicate'));
		}
	})
	.then(_commit => {
		return res.send('updated');
	})
	.catch((err) => {
		if (err.message === 'duplicate') {
			return res.send('duplicate')
		}else{
			console.error(err);
			return res.send('error')
		}
	})
});

[REQUIRED] Expected behavior

In firebase console, RTDB, admin/singleTask/done should be set to 1
&&
in firestore, col/doc1 should contain key: "val"

[REQUIRED] Actual behavior

Write is successfull in cloudfunctions, but not showing in console.

@google-oss-bot
Copy link
Contributor

This issue does not seem to follow the issue template. Make sure you provide all the required information.

@samtstern
Copy link
Contributor

@hkchakladar that's the intended behavior because it is writing back to the Database Emulator, which can't be seen by the console.

You can view the data by going to:
http://localhost:PORT/admin/singleTask/done.json?ns=YOUR_PROJECT_ID

Make sure to replace PORT with the port the RTDB emulator is using and YOUR_PROJECT_ID with your Firebase project ID.

@hkchakladar
Copy link
Author

Okay.

What about firestore?

And is there any way to write back to production database?

@samtstern
Copy link
Contributor

@hkchakladar for Firestore there's no easy way to view data in your browser, we're working on it!

If you want to write back to production, you should not run the DB emulators. So firebase emulators:start --only functions. Then any code that runs in the function will talk to production. Of course then you can't trigger the functions based on local DB events but that would be a strange combination anyway.

@samtstern
Copy link
Contributor

Closing this issue as I believe the question is now answered.

@anantanandgupta
Copy link

anantanandgupta commented Oct 13, 2019

i am hitting my head to figure out how to make my functions talk to emulated database ... all my functions are simply talking to database in the cloud. I want to debug / develop my application locally so that i can speed up the process. I have a huge list of APIs and they store/fetch the information from the realtime database. I am not sure how i can setup a local development environment with firebase cli so that i can work with the realtime database and development data locally. without even bothering on what is stored in the cloud database.

@hkchakladar
Copy link
Author

hkchakladar commented Oct 13, 2019

@anantanandgupta Start the emulators by using firebase emulators:start That doesn't talk to production database. I think you're starting by firebase serve.

@anantanandgupta
Copy link

@hkchakladar thanks it was helpful ... it is pointing to the local database now. Next is how to load the initial data (that to without triggering the db triggers (onCreate / onUpdate etc.)). If this is done ... my life is sorted ... my application i was all building on the real database all the time and it was really difficult to do something with the sample data in the live environment.

@samtstern
Copy link
Contributor

@anantanandgupta that's a known feature request and you can track it here:
#1167

Thanks for letting us know!

@anantanandgupta
Copy link

thanks @samtstern but that thread seems to be only focusing on firestore db, is the realtime db also in the same scope?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants