Algunas notas de los comandos NoSQL para trabajar con Firebase
Last active
December 16, 2022 14:28
-
-
Save codewithleader/0f0f13cebc58b2f7377e7311627b862a to your computer and use it in GitHub Desktop.
Firebase - Comandos CRUD
- Referencia al document
const usuariosRef = db.collection('usuarios');- Objeto
const usuario = {
nombre: 'Susana',
activo: false,
fechaNaci: 0,
salario: 1950
}- insert into usuarios ....
db.collection('usuarios')
.add( usuario )
.then( docRef => {
console.log( docRef )
})
.catch( e => console.log('error', e ))- update usuarios set activo = false where.... Esto actualiza solo la propiedad que se envia. Las demas quedan iguales. Si la propiedad que se envia no se encuentra entonces se crea.
usuariosRef
.doc('DcHhom5s03TCa8waNVBe')
.update({
activo: true
});- Update Destructivo: Update usuario reemplazando todas las propiedades por las seteadas
usuariosRef
.doc('DcHhom5s03TCa8waNVBe')
.set({
activo: true,
edad: 44,
});- delete from usuarios where id ='xx'
usuariosRef
.doc('DcHhom5s03TCa8waNVBe')
.delete()
.then( () => console.log('Borrado') )
.catch( e => console.log('error', e));- select * from usuarios;
usuariosRef
.onSnapshot( retornaDocumentos )usuariosRef.get().then( retornaDocumentos );- Select * from usuarios Where activo = true
usuariosRef.where('activo','==', true ).get().then( retornaDocumentos );- Select * from usuarios Where salario > 1800
usuariosRef.where('salario','>', 1800 )
.get().then( retornaDocumentos );-
Select * from usuarios
-- Where salario > 1800 and salario < 2300 Where salario between 1800 and 2300
usuariosRef.where('salario','>=', 1800 )
.where('salario', '<=', 2300 )
.get().then( retornaDocumentos );-
Select * from usuarios
Where salario > 1800 And activo == true
usuariosRef.where('salario','>=', 1800 )
.where('activo', '==', true )
.get().then( retornaDocumentos );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment