1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Node.js の Rest で Cloud Firestore のデータを削除 (Delete)

Last updated at Posted at 2020-02-01
firestore_delete_rest.js
#! /usr/bin/node
// ---------------------------------------------------------------
//	firestore_delete_rest.js
//
//					Feb/01/2020
//
// ---------------------------------------------------------------
var fs = require("fs")
var get_token = require('./get_token.js')

// ---------------------------------------------------------------
console.error ("*** 開始 ***")

const key_in=process.argv[2]
console.log (key_in)

const env = process.env
const json_str = fs.readFileSync (env.GOOGLE_APPLICATION_CREDENTIALS,'utf8')
const dict_aa = JSON.parse (json_str)
const project_id = dict_aa['project_id']
console.log(project_id)

const token = get_token.get_token_proc()

const project = 'project-jan25-2020'
const url="https://firestore.googleapis.com/v1/projects/" + project_id + "/databases/(default)/documents/cities/" + key_in

var Client = require('node-rest-client').Client

var client = new Client()

var args = {
    headers: { "Authorization": "Bearer " + token}
	}

try
	{
	client.delete(url, args, function (data, response) {
//			console.log(response)
			})
	console.error ("*** 終了 ***")
	}
	catch (error)
	{
	console.error ("*** error *** from client.get ***")
	console.error (error)
	}

// ---------------------------------------------------------------

get_token.js はこちら
Node.js の Rest で Cloud Firestore のデータを作成 (Create)

実行コマンド

export NODE_PATH=/usr/lib/node_modules
export GOOGLE_APPLICATION_CREDENTIALS="***.json"
./firestore_delete_rest.js t0921
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?